package com.ssy.lingxi.platform.manage.controller;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.manage.api.model.dto.area.AreaDTO;
import com.ssy.lingxi.platform.manage.api.model.vo.area.AreaVO;
import com.ssy.lingxi.platform.manage.api.model.vo.area.LocationVO;
import com.ssy.lingxi.platform.manage.api.model.vo.area.ProvinceVO;
import com.ssy.lingxi.platform.manage.config.ServiceConfig;
import com.ssy.lingxi.platform.manage.entity.base.Area;
import com.ssy.lingxi.platform.manage.service.IAreaService;
import com.ssy.lingxi.platform.manage.util.HttpUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author wrc
 * @version 2.0.0
 * @menu 省市区街道四级联动管理
 * @date 2020/7/20
 */
@RestController
@RequestMapping("/manage")
public class AreaController {

    @Resource
    private IAreaService areaService;

    /**
     * 根据ip获取城市
     * @param request HttpServletRequest请求数据
     * @return 操作结果
     */
    @GetMapping("/area/findCityByIP")
    public Wrapper<LocationVO> findCityByIP(HttpServletRequest request) {
        String ipAddr = HttpUtil.getIpAddr(request);
        String code= ServiceConfig.PLATFORM_MANAGE_GAO_DE_API_CODE;//固定写死
        return areaService.findCityByIP(code, ipAddr);

    }

    @ApiOperation(value = "根据省编码获取所有市编码")
    @GetMapping("/area/findCityCodeByProvinceCode")
    public Wrapper<List<String>> findCityCodeByProvinceCode(@RequestParam("provinceCodes") List<String> provinceCodes) {
        return areaService.findCityCodeByProvinceCode(provinceCodes);
    }

    @ApiOperation(value = "获取省市")
    @GetMapping("/area/findProvinceCity")
    public Wrapper<List<ProvinceVO>> findProvinceCity() {
        return areaService.findProvinceCity();
    }

    @ApiOperation(value = "查询省市区列表")
    @GetMapping("/area/all")
    public Wrapper<List<AreaVO>> areaAll() {
        return areaService.areaAll();
    }

    @ApiOperation(value = "查询省市区列表")
    @GetMapping("/area/list")
    public Wrapper<List<AreaVO>> areaList() {
        return areaService.areaList();
    }

    @ApiOperation(value = "根据父code查询省市区")
    @GetMapping("/area/by/pcode/all")
    public Wrapper<List<AreaVO>> areaByPcodeAll(AreaDTO request) {
        return areaService.areaByPcodeAll(request);
    }

    @ApiOperation(value = "根据code查询下级区域，不传参数默认获取所有省份")
    @GetMapping("/area/by/pcode")
    public Wrapper<List<Area>> areaByPcode(AreaDTO request) {
        return areaService.areaByPcode(request);
    }
}
